﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using HYRevitCode.FormUtility;
using QuickModel.GeothermalPipeQuickModel;

namespace QuickModel.Forms.GeothermalPipe
{
	public partial class GeothermalPipeSameSetForm : System.Windows.Forms.Form
	{
		public CloseGeothermalDlgType DlgCloseType
		{
			get
			{
				return this.m_DlgCloseType;
			}
		}

		public GeothermalPipeSameSetForm(UIDocument inputUIDoc)
		{
			this.InitializeComponent();
			this.m_uiDoc = inputUIDoc;
		}

		private void txtBoxSameLineColor_Click(object sender, EventArgs e)
		{
			ColorDialog colorDialog = new ColorDialog();
			colorDialog.AllowFullOpen = true;
			colorDialog.FullOpen = true;
			System.Drawing.Color xmlDataColor = ColorSet.GetXmlDataColor(this.txtBoxSameLineColor.Text);
			bool flag = !xmlDataColor.IsKnownColor;
			if (flag)
			{
				int[] array = new int[16];
				array[0] = ColorSet.GetIntAboutColor(xmlDataColor);
				colorDialog.CustomColors = array;
			}
			colorDialog.Color = xmlDataColor;
			DialogResult dialogResult = colorDialog.ShowDialog();
			bool flag2 = DialogResult.OK == dialogResult;
			if (flag2)
			{
				string newRGB = ColorSet.getNewRGB(colorDialog.Color.R);
				string newRGB2 = ColorSet.getNewRGB(colorDialog.Color.G);
				string newRGB3 = ColorSet.getNewRGB(colorDialog.Color.B);
				string text = string.Concat(new string[]
				{
					"█RGB ",
					newRGB,
					" ",
					newRGB2,
					" ",
					newRGB3
				});
				this.txtBoxSameLineColor.ForeColor = colorDialog.Color;
				this.txtBoxSameLineColor.Text = text;
			}
		}

		private void btnSameSetOK_Click(object sender, EventArgs e)
		{
			GeothermalFormData.LineTypeSupply = this.comBoxSameType.Text;
			GeothermalFormData.LineWidthSupply = this.comBoxSameWidth.Text;
			GeothermalFormData.LineColorSupply = this.txtBoxSameLineColor.Text;
			bool @checked = this.radAreaChange.Checked;
			if (@checked)
			{
				GeothermalFormData.IsArea = true;
				GeothermalFormData.IsLevel = false;
				this.m_DlgCloseType = CloseGeothermalDlgType.ByArea;
			}
			else
			{
				GeothermalFormData.IsArea = false;
				GeothermalFormData.IsLevel = true;
				this.m_DlgCloseType = CloseGeothermalDlgType.ByLevel;
			}
			base.DialogResult = DialogResult.OK;
		}

		private void GeothermalPipeSameSetForm_Load(object sender, EventArgs e)
		{
			base.Icon = Resource.YArchitechIcon;
			this.txtBoxSameLineColor.Text = "█RGB 000 255 255";
			this.radLevelChange.Checked = true;
			Dictionary<string, Element> allLineType = GetRevitProjectData.GetAllLineType(this.m_uiDoc.Document);
			GeothermalFormData.LineType = allLineType;
			this.comBoxSameWidth.Items.AddRange(GetRevitProjectData.LineWidth().ToArray());
			this.comBoxSameWidth.SelectedIndex = 13;
			this.AddControlGroup();
			this.m_ControlInfoManager = new ControlInfoManager(this, this.m_lstControlGroup, null, null);
			this.m_ControlInfoManager.SetControlInfoToForm();
			System.Drawing.Color xmlDataColor = ColorSet.GetXmlDataColor(this.txtBoxSameLineColor.Text);
			this.txtBoxSameLineColor.ForeColor = xmlDataColor;
			bool flag = !allLineType.Keys.ToArray<string>().Contains(this.comBoxSameType.Text);
			if (flag)
			{
				this.comBoxSameType.Items.Clear();
				this.comBoxSameType.Items.Add("实线");
				this.comBoxSameType.Items.AddRange(allLineType.Keys.ToArray<string>());
				this.comBoxSameType.SelectedItem = "实线";
			}
		}

		private void AddControlGroup()
		{
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.comBoxSameType, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.txtBoxSameLineColor, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.comBoxSameWidth, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.radAreaChange, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.radLevelChange, false));
		}

		private void btnSameSetCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void GeothermalPipeSameSetForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			bool flag = this.m_ControlInfoManager != null;
			if (flag)
			{
				this.m_ControlInfoManager.GetControlInfoToXml();
			}
		}

		private void GeothermalPipeSameSetForm_KeyDown(object sender, KeyEventArgs e)
		{
			bool flag = e.KeyValue == 27;
			if (flag)
			{
				base.DialogResult = DialogResult.Cancel;
			}
		}

		private void txtBoxSameLineColor_KeyPress(object sender, KeyPressEventArgs e)
		{
			e.Handled = true;
		}

		private void txtBoxSameLineColor_TextChanged(object sender, EventArgs e)
		{
			bool flag = string.IsNullOrWhiteSpace(this.txtBoxSameLineColor.Text);
			if (flag)
			{
				this.txtBoxSameLineColor.Text = this.defaultText;
				System.Drawing.Color xmlDataColor = ColorSet.GetXmlDataColor(this.txtBoxSameLineColor.Text);
				this.txtBoxSameLineColor.ForeColor = xmlDataColor;
			}
			try
			{
				bool flag2 = this.txtBoxSameLineColor.Text != "默认";
				if (flag2)
				{
					System.Drawing.Color color = System.Drawing.Color.FromArgb(int.Parse(this.txtBoxSameLineColor.Text.Split(new char[]
					{
						' '
					}).ElementAt(1)), int.Parse(this.txtBoxSameLineColor.Text.Split(new char[]
					{
						' '
					}).ElementAt(2)), int.Parse(this.txtBoxSameLineColor.Text.Split(new char[]
					{
						' '
					}).ElementAt(3)));
				}
			}
			catch (ArgumentOutOfRangeException)
			{
				this.txtBoxSameLineColor.Text = this.defaultText;
			}
		}

		private ControlInfoManager m_ControlInfoManager = null;

		private List<KeyValuePair<System.Windows.Forms.Control, bool>> m_lstControlGroup = new List<KeyValuePair<System.Windows.Forms.Control, bool>>();

		private UIDocument m_uiDoc = null;

		private CloseGeothermalDlgType m_DlgCloseType;

		private string defaultText = "█RGB 000 255 255";
	}
}
